package com.letsiot.applications.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.letsiot.applications.entity.SysRole;
import com.letsiot.applications.entity.enums.RoleType;
import com.letsiot.applications.service.SysRoleService;

@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("save")
    public int save(@RequestBody SysRole entity) {
        return sysRoleService.save(entity);
    }

    @DeleteMapping("delete")
    public int delete(Long id) {
        return sysRoleService.delete(id);
    }

    @PutMapping("update")
    public int update(@RequestBody SysRole entity) {
        return sysRoleService.update(entity);
    }

    @GetMapping("findById")
    public SysRole findById(Long id) {
        return sysRoleService.findById(id);
    }

    @GetMapping("getAll")
    public List<SysRole> getAll() {
        return sysRoleService.getAll();
    }

    @GetMapping("findByType")
    public Page<SysRole> findByType(int page, int size, RoleType roleType) {
        Pageable pageable = PageRequest.of(page, size);
        return sysRoleService.findByType(roleType, pageable);
    }
}
